package com.cainiao.controller;

import javafx.geometry.Pos;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.PostConstruct;
import javax.xml.crypto.dsig.keyinfo.RetrievalMethod;

/**
 * @author shkstart
 * @create 2021-08-04 12:36
 */
@Controller
public class TestController {

    @RequestMapping(value = "/")
    public String getIndex() {
        return "index";
    }

    /**
     * 表示这个方法支持 get 和 post
     *
     * @return
     */
    @RequestMapping(value = {"/test"},
            method = {RequestMethod.GET, RequestMethod.POST}
    )
    public String getTable() {
        return "success";
    }

    /**
     * 获取 get请求
     *
     * @return
     */
    @GetMapping("/testGetMapping")
    public String testGetMapping() {
        return "success";
    }

    /**
     * 获取 post请求
     *
     * @return
     */
    @PostMapping("/testPostMapping")
    public String testPostMapping() {
        return "success";
    }

    /**
     * method 指定请去为 put的请去
     *
     * @return
     */
    @RequestMapping(value = "/testPut", method = RequestMethod.PUT)
    public String testPut() {
        return "success";
    }

    /**
     * params 就是请求中需要带的参数
     * headers 就是请求的 头部信息【在网页 network中查看】
     *
     * @return
     */
    @RequestMapping(value = "/testParamsAndHeaders",
            params = {"username"},
            headers = {"host=localhost:8080"})
    public String testParamsAndHeaders() {
        return "success";
    }

    /**
     * RequestMapping 支持ant风格的请去：
     * 在 RequestMapping，中请求路中出现 问好 和 斜线不行
     * {XXX} 表示请求路径中的占位符
     * 可以使用注解 @PathVariable 注解来获取请求的参数
     *
     * @return
     */
    //@RequestMapping("/a?a/testAnt")
    //@RequestMapping("/a*a/testAnt")
    @RequestMapping("/**/testAnt")
    public String testAnt() {
        return "success";
    }


    @RequestMapping("/testPath/{id}/{username}")
    public String aa(@PathVariable("id") Integer id,
                     @PathVariable("username") String name) {
        System.out.println("id" + id + ",username" + name);
        return "success";
    }

    @RequestMapping("/param")
    public String testParam() {
        return "test_param";
    }

}
